'use strict';

const defaults = require('./src/defaults');
const musicQualities = require('./src/musicQualities');
const downloadTypes = require('./src/downloadTypes');
const downloadMultiple = require('./src/downloadMultiple');

/**
 * Start a deezer download.from module
 *
 * @param {String}  deezerUrl
 */
const dFi = async (deezerUrl, path = defaults.DOWNLOAD_DIR, quality = musicQualities.selectedQuality.id) => {
  try {
    const downloadType = await downloadTypes(deezerUrl);
    if (downloadType.type == 'unknown') {
      throw { error: 'Invalid url', message: 'Unknown url type' };
    }
    return downloadMultiple(downloadType, path, quality);
  } catch (err) {
    return err;
  }
};

module.exports = dFi;
